home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / gtlayout / source / lt_rebuild.c < prev    next >
C/C++ Source or Header  |  1999-04-19  |  7KB  |  354 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1998 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. /*****************************************************************************/
  15.  
  16. #include <stdarg.h>
  17.  
  18. /*****************************************************************************/
  19.  
  20. #include "Assert.h"
  21.  
  22. /*****************************************************************************/
  23.  
  24.  
  25. VOID
  26. LTP_Erase(LayoutHandle *Handle)
  27. {
  28.     struct Window *Window = Handle->Window;
  29.  
  30.     EraseRect(&Handle->RPort,Window->BorderLeft,Window->BorderTop,Window->Width - (Window->BorderRight + 1),Window->Height - (Window->BorderBottom + 1));
  31. }
  32.  
  33.  
  34. /*****************************************************************************/
  35.  
  36.  
  37. /****** gtlayout.library/LT_RebuildTagList ******************************************
  38. *
  39. *   NAME
  40. *    LT_RebuildTagList -- Rebuild the user interface after modifying it.
  41. *
  42. *   SYNOPSIS
  43. *    Success = LT_RebuildTagList(Handle,Clear,TagList);
  44. *       D0                         A0    D0     A1
  45. *
  46. *    BOOL LT_RebuildTagList(LayoutHandle *,BOOL,struct TagItem *);
  47. *
  48. *    Success = LT_RebuildTags(Handle,Clear,...);
  49. *
  50. *    BOOL LT_RebuildTags(LayoutHandle *,BOOL,...);
  51. *
  52. *   FUNCTION
  53. *    Certain aspects of the user interface can be changed at run time,
  54. *    such as button labels. This routine will let you rebuild the interface
  55. *    based upon the data supplied at creation time and your subsequent
  56. *    changes. Before you make any vital changes, it is recommended to
  57. *    lock the window using LT_LockWindow() in order to avoid clashes
  58. *    with the Intuition and GadTools subsystems.
  59. *
  60. *   INPUTS
  61. *    Handle - Pointer to LayoutHandle structure.
  62. *
  63. *    Clear - Pass in TRUE if you wish to have the window contents
  64. *        cleared before they are rebuild. This will introduce
  65. *        some visual hashing.
  66. *
  67. *    TagList - Attributes controlling the layout process.
  68. *
  69. *
  70. *    Valid tags include:
  71. *
  72. *    LAWN_Bounds (struct IBox *) - Boundaries in which the window
  73. *        should be centered.
  74. *
  75. *    LAWN_ExtraWidth (LONG) - Extra space to add to the window
  76. *        width.
  77. *
  78. *    LAWN_ExtraHeight (LONG) - Extra height to add to the window
  79. *        height.
  80. *
  81. *   RESULT
  82. *    Success - TRUE indicates that the interface was rebuilt,
  83. *        FALSE indicates trouble; it is recommended to
  84. *        call LT_DeleteHandle() on your LayoutHandle as
  85. *        soon as possible as the previous operation may
  86. *        have left the user interface in an inoperable
  87. *        state.
  88. *
  89. ******************************************************************************
  90. *
  91. */
  92.  
  93. BOOL LIBENT
  94. LT_RebuildTagList(REG(a0) LayoutHandle *handle,REG(d0) BOOL clear,REG(a1) struct TagItem *TagParams)
  95. {
  96.     struct TagItem    *item,
  97.                     *list;
  98.     struct IBox        *bounds = NULL;
  99.     LONG             RightEdge,
  100.                      BottomEdge;
  101.  
  102.     list = TagParams;
  103.  
  104.     while(item = NextTagItem(&list))
  105.     {
  106.         switch(item->ti_Tag)
  107.         {
  108.             case LAWN_Bounds:
  109.  
  110.                 bounds = (struct IBox *)item->ti_Data;
  111.                 break;
  112.         }
  113.     }
  114.  
  115.     if(handle)
  116.     {
  117.         struct Gadget    *gadget,
  118.                         *next;
  119.         ObjectNode        *node;
  120.         LONG             left,top;
  121.         struct IBox         newBounds;
  122.         struct Image    **ImagePtr;
  123.  
  124.         if(!handle->SizeVerified)
  125.         {
  126.             LTP_StripGadgets(handle,handle->List);
  127.  
  128.             #ifdef DO_BOOPSI_KIND
  129.             {
  130.                 LTP_StripGadgets(handle,(struct Gadget *)handle->BOOPSIList);
  131.             }
  132.             #endif    /* DO_BOOPSI_KIND */
  133.         }
  134.         gadget = handle->List;
  135.  
  136.         while(gadget)
  137.         {
  138.             if(GETOBJECT(gadget,node))
  139.             {
  140.                 LTP_PutStorage(node);
  141.  
  142.                 ImagePtr = NULL;
  143.  
  144.                 switch(node->Type)
  145.                 {
  146.                     #ifdef DO_GAUGE_KIND
  147.                     {
  148.                         case GAUGE_KIND:
  149.  
  150.                             node->Special.Gauge.LastPercentage = -1;
  151.                             break;
  152.                     }
  153.                     #endif    /* DO_GAUGE_KIND */
  154.  
  155.                     case BUTTON_KIND:
  156.  
  157.                         ImagePtr = &node->Special.Button.ButtonImage;
  158.                         break;
  159.  
  160.                     case PICKER_KIND:
  161.  
  162.                         ImagePtr = &node->Special.Picker.Image;
  163.                         break;
  164.  
  165.                     case TAPEDECK_KIND:
  166.  
  167.                         ImagePtr = &node->Special.TapeDeck.ButtonImage;
  168.                         break;
  169.  
  170.                     case INCREMENTER_KIND:
  171.  
  172.                         ImagePtr = &node->Special.Incrementer.Image;
  173.                         break;
  174.  
  175.                     case STRING_KIND:
  176.                     case FRACTION_KIND:
  177.  
  178.                         if(!node->Special.String.Backup)
  179.                             node->Special.String.Backup = (STRPTR)LTP_Alloc(handle,node->Special.String.MaxChars + 1);
  180.  
  181.                         if(node->Special.String.Backup)
  182.                         {
  183.                             strcpy(node->Special.String.Backup,((struct StringInfo *)gadget->SpecialInfo)->Buffer);
  184.  
  185.                             node->Special.String.String = node->Special.String.Backup;
  186.                         }
  187.  
  188.                         node->Special.String.Picker = NULL;
  189.  
  190.                         node->Special.String.LeftIncrementer    = NULL;
  191.                         node->Special.String.RightIncrementer    = NULL;
  192.  
  193.                         break;
  194.  
  195.                     case TEXT_KIND:
  196.  
  197.                         node->Special.Text.Picker = NULL;
  198.                         break;
  199.  
  200.                     case INTEGER_KIND:
  201.  
  202.                         node->Special.Integer.LeftIncrementer    = NULL;
  203.                         node->Special.Integer.RightIncrementer    = NULL;
  204.  
  205.                         break;
  206.                 }
  207.  
  208.                 if(ImagePtr)
  209.                 {
  210.                     DisposeObject(*ImagePtr);
  211.  
  212.                     *ImagePtr = NULL;
  213.                 }
  214.  
  215.                 node->Host = NULL;
  216.             }
  217.  
  218.             gadget = gadget->NextGadget;
  219.         }
  220.  
  221.         FreeGadgets(handle->List);
  222.  
  223.         handle->List = NULL;
  224.  
  225.         #ifdef DO_BOOPSI_KIND
  226.         {
  227.             gadget = (struct Gadget *)handle->BOOPSIList;
  228.  
  229.             while(gadget)
  230.             {
  231.                 next = gadget->NextGadget;
  232.  
  233.                 if(GETOBJECT(gadget,node))
  234.                 {
  235.                     DisposeObject(gadget);
  236.  
  237.                     if(node->Type == BOOPSI_KIND)
  238.                     {
  239.                         if(node->Special.BOOPSI.ClassBase)
  240.                         {
  241.                             CloseLibrary(node->Special.BOOPSI.ClassBase);
  242.  
  243.                             node->Special.BOOPSI.ClassBase = NULL;
  244.                         }
  245.                     }
  246.  
  247.                     node->Host = NULL;
  248.                 }
  249.  
  250.                 gadget = next;
  251.             }
  252.  
  253.             handle->BOOPSIList = NULL;
  254.             handle->BOOPSIPrevious = NULL;
  255.         }
  256.         #endif    /* DO_BOOPSI_KIND */
  257.  
  258.         LTP_Free(handle,handle->GadgetArray,sizeof(struct Gadget *) * handle->Count);
  259.  
  260.         handle->GadgetArray = NULL;
  261.  
  262.         handle->Count = handle->Index = 0;
  263.  
  264.         LTP_ResetGroups(handle->TopGroup);
  265.  
  266.         if(!bounds)
  267.         {
  268.             bounds = &newBounds;
  269.  
  270.             newBounds.Left        = 0;
  271.             newBounds.Top        = 0;
  272.             newBounds.Width        = handle->Window->Width;
  273.             newBounds.Height    = handle->Window->Height;
  274.         }
  275.  
  276.         left        = handle->Window->BorderLeft;
  277.         top            = handle->Window->BorderTop;
  278.         RightEdge    = handle->Window->BorderRight;
  279.         BottomEdge    = handle->Window->BorderBottom;
  280.  
  281.         if(!handle->FlushLeft)
  282.         {
  283.             left        += handle->InterWidth;
  284.             RightEdge    += handle->InterWidth;
  285.         }
  286.  
  287.         if(!handle->FlushTop)
  288.         {
  289.             top            += handle->InterHeight;
  290.             BottomEdge    += handle->InterHeight;
  291.         }
  292.  
  293.         LTP_CreateGadgets(handle,bounds,left,top,left + RightEdge,top + BottomEdge);
  294.  
  295.         if(handle->Failed)
  296.         {
  297.             handle->SizeVerified = FALSE;
  298.  
  299.             LTP_Erase(handle);
  300.  
  301.             RefreshWindowFrame(handle->Window);
  302.  
  303.             return(FALSE);
  304.         }
  305.  
  306.         if(clear)
  307.         {
  308.             LTP_Erase(handle);
  309.  
  310.             if(!handle->SizeVerified)
  311.                 RefreshWindowFrame(handle->Window);
  312.         }
  313.  
  314.         handle->SizeVerified = FALSE;
  315.  
  316.         LTP_AddGadgets(handle);
  317.  
  318.         LTP_SelectInitialActiveGadget(handle);
  319.  
  320.         return(TRUE);
  321.     }
  322.     else
  323.         return(FALSE);
  324. }
  325.  
  326.  
  327. /*****************************************************************************/
  328.  
  329.  
  330. BOOL
  331. LT_RebuildTags(LayoutHandle *Handle,BOOL Clear,...)
  332. {
  333.     va_list VarArgs;
  334.     BOOL    Result;
  335.  
  336.     va_start(VarArgs,Clear);
  337.     Result = LT_RebuildTagList(Handle,Clear,(struct TagItem *)VarArgs);
  338.     va_end(VarArgs);
  339.  
  340.     return(Result);
  341. }
  342.  
  343.  
  344. /*****************************************************************************/
  345.  
  346.  
  347. BOOL LIBENT
  348. LT_Rebuild(REG(a0) LayoutHandle *handle,REG(a1) struct IBox *bounds,REG(a2) LONG extraWidth,REG(d0) LONG extraHeight,REG(d1) BOOL clear)
  349. {
  350.     return(LT_RebuildTags(handle,clear,
  351.         LAWN_Bounds,bounds,
  352.     TAG_DONE));
  353. }
  354.